package controller

import (
	"github.com/gin-gonic/gin"
	"strconv"
	"yak.admin/src/entity"
	"yak.admin/src/middleware"
	"yak.admin/src/repository"
	"yak.admin/src/service"
	"yak.admin/src/util"
)

func Reports(ctx *gin.Context)  {
	user := ctx.MustGet(util.UserKey).(entity.User)
	p := ctx.DefaultQuery("page", "1")
	page, _ := strconv.Atoi(p)
	repos := repository.ReportRepository{UserId: user.Id, Page: page, Pagesize: 15}
	middleware.ResultSuccess(ctx, "", map[string]interface{}{
		"list": repos.FindAll(),
	})
}

func Message(ctx *gin.Context) {
	user := ctx.MustGet(util.UserKey).(entity.User)
	search := repository.UserRepository{}
	page := ctx.DefaultQuery("page", "1")
	p, _ := strconv.Atoi(page)
	behavior := service.BehaviorService{}
	behavior.FlushMessageTimes(user.Id)
	middleware.ResultSuccess(ctx, "", map[string]interface{}{
		"list": search.Messages(user.Id, p, 15),
	})
}

func Configs(ctx *gin.Context) {
	user := ctx.MustGet(util.UserKey).(entity.User)
	behavior := service.BehaviorService{}
	middleware.ResultSuccess(ctx, "", map[string]interface{}{
		"message_times": behavior.ReadMessageTimes(user.Id),
	})
}
